package com.hottv.meeting.videomeeting;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentUris;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.RemoteException;
import android.os.SystemClock;
import android.provider.DocumentsContract;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.hottv.meeting.videomeeting.common.MeetingConfig;
import com.hottv.meeting.videomeeting.common.MeetingUtils;
import com.hottv.meeting.videomeeting.module.edp.EDPService;
import com.hottv.meeting.videomeeting.module.edp.data.MeetingInfo;
import com.hottv.meeting.videomeeting.module.file.activity.FolderActivity;
import com.hottv.meeting.videomeeting.module.meeting.InfoAccessImpl;
import com.hottv.meeting.videomeeting.module.meeting.MeetUtils;
import com.hottv.meeting.videomeeting.module.meeting.bean.HotMessage;
import com.hottv.meeting.videomeeting.module.meeting.data.MeetInfo;
import com.hottv.meeting.videomeeting.module.meeting.data.MemSelectInfo;
import com.hottv.meeting.videomeeting.module.white.DoCallback;
import com.hottv.meeting.videomeeting.module.white.WhiteAPI;
import com.hottv.meeting.videomeeting.module.white.WhiteUtils;

import java.io.IOException;
import java.util.Arrays;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

public class LoginActivity extends Activity {

    private EditText mRoomTxt;
    private EditText mUserTxt;

    private Context mContext;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        mContext = this;


//        startService(new Intent(mContext, EDPService.class));

        init();
    }

    private void init()
    {
        mRoomTxt = (EditText)findViewById(R.id.edit_room_name);
        mUserTxt = (EditText)findViewById(R.id.edit_user_name);
        mRoomTxt.setText("969401784");
    }

    @Override
    protected void onResume()
    {
        super.onResume();
        InfoAccessImpl.getInstance(mContext);
    }


    @Override
    protected void onDestroy()
    {
        super.onDestroy();
        InfoAccessImpl.getInstance(mContext).unbindAuthService();
    }

    public void onClickJoinBroadcaster(View view){

        MeetInfo info = new MeetInfo();
        info.startTime = String.valueOf(System.currentTimeMillis());
        info.status = "0";
        Intent i = new Intent(this, Meeting2Activity.class);
        Gson gson =new Gson();
        String abc = gson.toJson(info);
        i.putExtra(MeetingConfig.MeetingDATA,abc);
        startActivity(i);


//        Intent intent = new Intent(LoginActivity.this,FolderActivity.class);
//        startActivityForResult(intent,1);
//        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
//        //intent.setType(“image/*”);//选择图片
//        //intent.setType(“audio/*”); //选择音频
//        //intent.setType(“video/*”); //选择视频 （mp4 3gp 是android支持的视频格式）
//        //intent.setType(“video/*;image/*”);//同时选择视频和图片
//        intent.setType("*/*");//无类型限制
//        intent.addCategory(Intent.CATEGORY_OPENABLE);
//        startActivityForResult(intent, 1);


//        String deviceId = "";
//        try{
//            deviceId = InfoAccessImpl.getInstance(mContext).getInfoData(InfoAccessImpl.DEVICEID,"");
//        }catch (RemoteException e)
//        {
//            e.printStackTrace();
//        }
//        Log.i(MeetingConfig.TAG,"deviceId:"+deviceId);
//        MeetingUtils.sendToEDP(123123321,"4719230412384102","2347298792834345");

//        MeetingUtils.getMeetingInfo(mContext, new DoCallback() {
//            @Override
//            public void onSuccess(String info) {
//                Log.i(MeetingConfig.TAG,"onSuccess");
//            }
//
//            @Override
//            public void onFailor(String info) {
//                Log.i(MeetingConfig.TAG,"onFailor");
//            }
//
//            @Override
//            public void onProcess(String info) {
//                Log.i(MeetingConfig.TAG,"onProcess");
//            }
//        });

//        String roomStr = mRoomTxt.getText().toString();
//        int userStr = 0;
//        try{
//            userStr = Integer.parseInt(mUserTxt.getText().toString());
//        }
//        catch (NumberFormatException e)
//        {
//            e.printStackTrace();
//        }
//
//
//       if(TextUtils.isEmpty(roomStr) || userStr==0)
//       {
//           Log.i(MeetingConfig.TAG,"please input room and user");
//           return;
//       }
//
//        Intent i = new Intent(this, MeetingActivity.class);
//        i.putExtra(MeetingConfig.ACTION_KEY_ROOM_ID, roomStr);
//        i.putExtra(MeetingConfig.ACTION_KEY_USER_ID, userStr);
//        i.putExtra(MeetingConfig.ACTION_KEY_USER_TYPE, MeetingConfig.BROADCASTER_TYPE);
//
//        startActivity(i);
    }

    public void onClickJoinAudience(View view){

        String roomStr = mRoomTxt.getText().toString();
        if(TextUtils.isEmpty(roomStr))
        {
            Log.i(MeetingConfig.TAG,"please input room and user");
            return;
        }

        Intent i = new Intent(this, Meeting2Activity.class);
        MeetingInfo info =new MeetingInfo();
        info.fromUserName = "程文强";
        info.content.startTime = System.currentTimeMillis();
        info.msgId = System.currentTimeMillis();
        info.content.meetingId =roomStr;
        Gson gson=new Gson();
        String dataStr =  gson.toJson(info);
        i.putExtra(MeetingConfig.MeetingDATA_Incall,dataStr);

        startActivity(i);
    }

    public void onUpload(View view)
    {
        String roomStr = mRoomTxt.getText().toString();
        Intent i = new Intent(this, IncallActivity.class);
        MeetingInfo info =new MeetingInfo();
        info.fromUserName = "程文强";
        info.content.startTime = System.currentTimeMillis();
        info.msgId = System.currentTimeMillis();
        info.content.meetingId =roomStr;
        Gson gson=new Gson();
        String dataStr =  gson.toJson(info);
        i.putExtra(MeetingConfig.MeetingDATA_Incall,dataStr);

        startActivity(i);
//        AlertDialog.Builder builder = new AlertDialog.Builder(this);
//        builder.setTitle("主播设置");
//        String nickName =  "你好";
//        builder.setMessage(nickName +"请求设置为主播,是否同意？");
//        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
//            @Override
//            public void onClick(DialogInterface dialog, int which) {
//                dialog.dismiss();
//            }
//        });
//
//        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
//            @Override
//            public void onClick(DialogInterface dialog, int which) {
//                dialog.dismiss();
//            }
//        });
//
//        builder.create().show();
//        Gson gson =new Gson();
//        HotMessage msg = MeetUtils.getRequestHotMessage(this,7);
//         String json = gson.toJson(msg);
//        Log.i("chengwenqiang","json:"+json);
//        HotMessage abc =  gson.fromJson(json,HotMessage.class);
//        Log.i("chengwenqiang","message:"+abc);
//        Intent i = new Intent(this, IncallActivity.class);
//        MeetingInfo info =new MeetingInfo();
//        info.fromUserName = "程文强";
//        info.content.startTime = System.currentTimeMillis();
//        info.msgId = System.currentTimeMillis();
//        info.content.meetingId = MeetingUtils.getUnifykeys(mContext)+"2141";
//        Gson gson=new Gson();
//        String dataStr =  gson.toJson(info);
//        i.putExtra(MeetingConfig.MeetingDATA_Incall,dataStr);
//
//        startActivity(i);
//        WhiteUtils.getPNG("/sdcard/download/08宋超.ppt", new DoCallback() {
//            @Override
//            public void onSuccess(String info) {
//               Log.i(MeetingConfig.TAG,"success:"+info);
//            }
//
//            @Override
//            public void onFailor(String info) {
//               Log.e(MeetingConfig.TAG,"error info:"+info);
//            }
//
//            @Override
//            public void onProcess(String info) {
//
//            }
//        });
    }


}
